/*
 * @Author: mayufo
 * @Date: 2020-02-17 00:56:20
 * @LastEditTime : 2020-02-17 00:57:19
 * @Description: 
 * @FilePath: /node/05/code/mysql-demo/demo1.js
 */
var mysql = require('mysql');

// 创建连接
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'me',
    password: 'secret',
    database: 'my_db'
});
// 连接数据库
connection.connect();

// 执行数据库
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
    if (error) throw error;
    console.log('The solution is: ', results[0].solution);
});

// 关闭连接
connection.end();